﻿using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace VideoPlayer.Entity
{
    public static class DbContext
    {
        public static SqlSugarScope Db = null;

        public static void SetConnectionString(string connStr)
        {
            if (Db is null)
            {
                Db = new SqlSugarScope(new ConnectionConfig()
                {
                    DbType = DbType.Sqlite,
                    ConnectionString = connStr,
                    IsAutoCloseConnection = true
                },
                       db =>
                       {
                           db.DbMaintenance.CreateDatabase();
                           db.CodeFirst.InitTables(typeof(PlaylistItemDb));
                       });
            }
            else
            {
                Db.CurrentConnectionConfig.ConnectionString = connStr;
            }

        }
    } 

}
